/**Trigger Name: NMRContractSummary 
 * Author: Accenture
 * Date: 4/19/2012
 * Requirement/Project Name: NMR
 * Requirement Description: Trigger for creation or update of opportunity 
                            for each Contract created in CRM
 */

trigger NMRContractSummary on Contract_Summary__c (before insert) {
    
    Map<string,Contract_Summary__c> contractMap = new Map<string,Contract_Summary__c>();
    set<Id> accntIdSet = new set<Id>();
    Map<string,Contract_Summary__c> opptyMap = new Map<string,Contract_Summary__c>();   
    
    for(Contract_Summary__c contSummary:Trigger.new){
       if(Trigger.ISINSERT){
           if(contSummary.account_Id__c != NULL){        
              accntIdSet.add(contSummary.account_Id__c);    
              if(contSummary.Opportunity_Id__c!= Null){
                    opptyMap.put(contSummary.Opportunity_Id__c,contSummary);                        
              }
              else{
                  contractMap.put(contSummary.Id, contSummary);
      }
      }
    }  
}
    if(accntIdSet.size()>0){
          NMRCreateUpdateOpptyfromContract.createOppty(contractMap,opptyMap,accntIdSet);
    }    
}